// vect.h -- Vector class with <<, more state

#ifndef VECTOR_H
#define VECTOR_H 0x00

#include <iostream>

// To set the Vector object, call it in the namespace Vector
#define SET_Parameter_Vector(n1, n2, form)                  \
    mode = form;                                            \
    if (form == RECT) {                                     \
        x = n1;                                             \
        y = n2;                                             \
        set_mag();                                          \
        set_ang();                                          \
    } else if (form == POL) {                               \
        mag = n1;                                           \
        ang = n2;                                           \
        set_x();                                            \
        set_y();                                            \
    } else {                                                \
        cout << "Incorrect 3rd argument to Vector() -- ";   \
        cout << "vector set to 0\n";                        \
        x = y = mag = ang = 0.0;                            \
        mode = RECT;                                        \
    }


namespace VECTOR {
    class Vector {
    public:
        enum Mode {RECT, POL};
        // RECT for rectangular, POL for Polar modes
    private:
        double x;   // horizontal value
        double y;   // vertical value
        double mag; // length of vector
        double ang; // direction of vector in degrees
        Mode mode;  // RECT or POL
    // private methods for settings values
        void set_mag();
        void set_ang();
        void set_x();
        void set_y();
    public:
        Vector();
        Vector(double n1, double n2, Mode form = RECT);
        void reset(double n1, double n2, Mode form = RECT);
        ~Vector();
        double xval() const {return x; }        // report x value
        double yval() const {return y; }        // report y value
        double magval() const {return mag; }    // report mag value
        double angval() const {return ang; }    // report ang value
        void polar_mode();
        void rect_mode();
    // operator overloading
        Vector operator+(const Vector & b) const;
        Vector operator-(const Vector & b) const;
        Vector operator-() const;
        Vector operator*(double n) const;
        bool operator==(const Vector &rhs) const;
        bool operator!=(const Vector &rhs) const;
    // friends
        friend Vector operator*(double n, const Vector & a);
        friend std::ostream & operator<<(std::ostream & os, const Vector & v);
    };
} // end namespace VECTOR

#endif // VECTOR_H
